const { dataSource } = require("./data-source");

dataSource
  .initialize()
  .then(function () {
    var category1 = {
      name: "语言",
    };
    var category2 = {
      name: "编程",
    };

    var post = {
      title: "测试中文3",
      text: "测试中文是否可以使用.",
      categories: [category1, category2],
    };

    var postRepository = dataSource.getRepository("Post");
    postRepository
      .save(post)
      .then(function (savedPost) {
        console.log("Post has been saved: ", savedPost);
        console.log("Now lets load all posts: ");

        return postRepository.find();
      })
      .then(function (allPosts) {
        console.log("All posts: ", allPosts);
      });
  })
  .catch(function (error) {
    console.log("Error: ", error);
  });
